﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using Models;
using System.Threading.Tasks;

public partial class Admin_shop_SendGoods : AdminBase
{
    public int _Id = 0;
    public string adminid;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";
        adminid = Session["adminID"].ToString();
        if (!string.IsNullOrEmpty(Request.Params["ID"]))
        {
            _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);
        }
        if (!Page.IsPostBack)
        {
            Entities mydb = new Entities();
            {
                //下家：-3用户取消，-2导入待处理，-1已提交未对账，0已提交已对账待付款，1已付款已导出，2已发货，3已收货，4已评价,
                //上家：-3用户取消，-1已提交未对账，此时“下家”可申请退款，0已提交已对账待付款，1已付款已导出，2已发货，3已收货，4已评价

                S_Order Lfb = mydb.S_Order.SingleOrDefault(p => p.OrderID == _Id);
                txtName.Text = Lfb.OPeople;
                txtTel.Text = Lfb.OTel;
                OProvance.Text = Lfb.OProvance;
                OCity.Text = Lfb.OCity;
                ODistrict.Text = Lfb.ODistrict;
                OAddress.Text = Lfb.OAddress;
                RadioButtonList1.SelectedValue = Lfb.OState.ToString();
                if (!string.IsNullOrEmpty(Lfb.OPostway))
                    ddrCompany.SelectedItem.Text = Lfb.OPostway.ToString();
                if (!string.IsNullOrEmpty(Lfb.OPostCode))
                    txtCode.Text = Lfb.OPostCode.ToString();

                var stringid = _Id.ToString();

                rptList.DataSource = mydb.Order_Log.Where(w => w.OrderID == stringid && w.OrderType == "S_Order").ToList();
                rptList.DataBind();

                if (Lfb.OPayState == 1)
                    Labelpay.Text = "<p style =\"padding: 1px 1px;font-size:12px;line-height:1.5;border - radius: 3px;background-color:#68ed55;; border-color:##68ed55;;color:#FFFFFF;text-align:center; width:220px\">已支付" + Lfb.OpayTime + "</p>";
                else
                    Labelpay.Text = "<p style =\"padding: 1px 1px;font-size:12px;line-height:1.5;border-radius: 3px;background-color:#333;; border-color:##ed5565;;color:#FFFFFF;text-align:center; width:120px\">待支付</p>";

                LabePost.Text = "   ￥" + Lfb.OLastPrice + "    (￥" + Lfb.OpostPrice + ")";

            }
        }
    }

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
        {
            int ostat = int.Parse(RadioButtonList1.SelectedValue);

            var model = mydb.S_Order.Where(x => x.OParentId == _Id || x.OrderID == _Id);//全部
            foreach (var yorder in model)
            {
                yorder.OPostCom = ddrCompany.SelectedValue.Replace(" ", "");
                yorder.OPostway = ddrCompany.SelectedItem.Text.Replace(" ", "");
                yorder.OPostCode = txtCode.Text.Trim();
                yorder.OPostState = 1;
                yorder.OState = int.Parse(RadioButtonList1.SelectedValue);
                yorder.OPeople = txtName.Text.Trim();
                yorder.OTel = txtTel.Text.Trim();
                yorder.OProvance = OProvance.Text.Trim();
                yorder.OCity = OCity.Text.Trim();
                yorder.ODistrict = ODistrict.Text.Trim();
                yorder.OAddress = OAddress.Text.Trim();
            }
            mydb.SaveChanges();
            Response.Write("<script> var success=1;</script>");
            _rky.SaveOrderLogs("S_Order", _Id.ToString(), ostat, TextRemarks.Text, adminid, "PC");
        }
    }



    public string getOrderState(string OState)
    {
        string Result = "";
        int state = int.Parse(OState);
        switch (state)
        {
            case -3: Result = "<div style=\"padding: 1px 1px;font-size:12px;line-height:1.5;border - radius: 3px;background-color:#ccc; border-color:#ed5565;;color:#FFFFFF;text-align:center;\">作 废</div>"; break;
            case -2: Result = "<div style=\"padding: 1px 1px;font-size:12px;line-height:1.5;border - radius: 3px;background-color:#ccc; border-color:#ed5565;;color:#FFFFFF;text-align:center;\">已取消</div>"; break;
            case -1: Result = "<div style=\"padding: 1px 1px;font-size:12px;line-height:1.5;border - radius: 3px;background-color:#ed5565; border-color:#ed5565;;color:#FFFFFF;text-align:center;\">待确定</div>"; break;
            case 1: Result = "<div style=\"padding: 1px 1px;font-size:12px;line-height:1.5;border - radius: 3px;background-color:#ccc; border-color:#ccc;;color:#FFFFFF;text-align:center;\">已支付未发货</div>"; break;

            case 2: Result = "<div style=\"padding: 1px 1px;font-size:12px;line-height:1.5;border - radius: 3px;background-color:#3db934; border-color:#ed5565;;color:#FFFFFF;text-align:center;\">已经发货</div>"; break;


        }
        return Result;
    }


}

